include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../common)

 # 查找 OpenSSL 库
 find_package(OpenSSL REQUIRED COMPONENTS SSL Crypto)

 if (OpenSSL_FOUND)
     include_directories(${OPENSSL_INCLUDE_DIR})
     link_libraries(${OPENSSL_LIBRARIES})
 else()
     message(FATAL_ERROR "OpenSSL not found. Please install OpenSSL.")
 endif()
 

find_package(Qt5 REQUIRED COMPONENTS
    Core
    Widgets 
    Location
    Network
    Sql
    WebChannel
    WebEngine
    WebEngineCore
    WebEngineWidgets
    WebSockets
    WebView
    Xml
)

set(test_src
    main.cpp
    # ../database/SQLiteUtils.cpp
    App.cpp
    TcpClient.cpp
)

qt5_add_resources(test_qrc_FILES
)


if(ANDROID)
    add_library(test SHARED
        ${test_src}
        ${test_qrc_FILES}
    )
elseif(WIN32 AND CMAKE_BUILD_TYPE MATCHES "Release")
    add_executable(test WIN32
        ${test_src}
        ${test_qrc_FILES}
    )
else()
    add_executable(test
        ${test_src}
        ${test_qrc_FILES}
    )
endif()

target_link_libraries(test
    PRIVATE 
    Qt5::Core
    Qt5::Widgets
    Qt5::Location
    Qt5::Network
    Qt5::Sql
    common
)

message(CMAKE_COMMAND:${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:test> $<TARGET_FILE_DIR:test>)
# 在生成后处理Windeployqt，用于处理图标资源
if(WIN32)
    add_custom_command(TARGET test POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_if_different
            $<TARGET_FILE:test>
            $<TARGET_FILE_DIR:test>
    )
    add_custom_command(TARGET test POST_BUILD
        COMMAND ${Qt_PATH}/bin/windeployqt.exe --no-translations --no-quick-import --no-angle --no-opengl-sw
            $<TARGET_FILE_DIR:test>
    )
endif()


# 把配置文件复制到安装目录下
add_custom_command(TARGET test POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_if_different
    ${CMAKE_CURRENT_SOURCE_DIR}/database/sql/test.sql
    $<TARGET_FILE_DIR:test>/database/sql/test.sql
)
# 把配置文件复制到安装目录下
add_custom_command(TARGET test POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_if_different
    ${CMAKE_CURRENT_SOURCE_DIR}/database/sql/boost_chat.sql
    $<TARGET_FILE_DIR:test>/database/sql/boost_chat.sql
)
